package com.yi.controller;

import com.yi.model.User;
import com.yi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 数据库用户控制
 * @author YI
 * @date 2018-3-19 09:25:29
 */
@Controller
@RequestMapping("/api")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/db")
    public ModelAndView testDB(Integer id){
        ModelAndView modelAndView = new ModelAndView();

        List<User> user = userService.findUser(id);
        if (user != null &&user.size() > 0) {
            modelAndView.addObject("user", user.get(0));
        }

        // /index的路径为resources\templates\index.ftl
        modelAndView.setViewName("/index");

        return modelAndView;
    }
}
